package asteroids.model.programs.statements.ActionStatements;

import asteroids.model.programs.expressions.Expression;
import asteroids.model.programs.expressions.BasicExpressions.DoubleLiteral;
import asteroids.model.programs.statements.ActionStatement;
import asteroids.model.programs.types.Type;


public class TurnStatement extends ActionStatement {
	
	public TurnStatement(int line, int column, Expression amount) {
		super(line, column);
		this.amount = amount;
	}

	@Override
	public void execute() {
		this.getProgram().getSelf().rotate(((DoubleLiteral) this.getAmount().getResult()).getValue());
	}
	
	public Expression getAmount() {
		return this.amount;
	}

	private Expression amount;

	@Override
	public Expression getExpression() {
		return amount;
	}
	
	@Override
	public String typeCheckStatement(String errorMessage) {
		String newErrorMessage = getExpression().typeCheckExpression(errorMessage);
		
		if(getExpression().getType()!= Type.DOUBLE){
			String addErrorMessage = ("The expression at line " + getExpression().getLine()
								+ " and column " + getExpression().getLine() + " is of type "
								+ getExpression().getType() + " and should be of type " + Type.DOUBLE + "\n");
			if(newErrorMessage == null) newErrorMessage = addErrorMessage;
			else newErrorMessage += addErrorMessage;
		}
		
		return newErrorMessage;
	}
	

}
